home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / slib / require.scm < prev    next >
Encoding:
Text File  |  1995-05-16  |  10.7 KB  |  345 lines

  1. ;;;; Implementation of VICINITY and MODULES for Scheme
  2. ;Copyright (C) 1991, 1992, 1993, 1994 Aubrey Jaffer
  3. ;
  4. ;Permission to copy this software, to redistribute it, and to use it
  5. ;for any purpose is granted, subject to the following restrictions and
  6. ;understandings.
  7. ;
  8. ;1.  Any copy made of this software must include this copyright notice
  9. ;in full.
  10. ;
  11. ;2.  I have made no warrantee or representation that the operation of
  12. ;this software will be error-free, and I am under no obligation to
  13. ;provide any services, by way of maintenance, update, or otherwise.
  14. ;
  15. ;3.  In conjunction with products arising from the use of this
  16. ;material, there shall be no use of my name in any advertising,
  17. ;promotional, or sales literature without prior written consent in
  18. ;each case.
  19.  
  20. (define *SLIB-VERSION* "2a2")
  21.  
  22. ;;; Standardize msdos -> ms-dos.
  23. (define software-type
  24.   (cond ((eq? 'msdos (software-type))
  25.      (lambda () 'ms-dos))
  26.     (else software-type)))
  27.  
  28. (define (user-vicinity)
  29.   (case (software-type)
  30.     ((VMS)    "[.]")
  31.     (else    "")))
  32.  
  33. (define program-vicinity
  34.   (let ((*vicinity-suffix*
  35.      (case (software-type)
  36.        ((NOSVE)    '(#\: #\.))
  37.        ((AMIGA)    '(#\: #\/))
  38.        ((UNIX)    '(#\/))
  39.        ((VMS)    '(#\: #\]))
  40.        ((MS-DOS WINDOWS ATARIST OS/2)    '(#\\))
  41.        ((MACOS THINKC)    '(#\:)))))
  42.     (lambda ()
  43.       (let loop ((i (- (string-length *load-pathname*) 1)))
  44.     (cond ((negative? i) "")
  45.           ((memv (string-ref *load-pathname* i)
  46.              *vicinity-suffix*)
  47.            (substring *load-pathname* 0 (+ i 1)))
  48.           (else (loop (- i 1))))))))
  49.  
  50. (define sub-vicinity
  51.   (case (software-type)
  52.     ((VMS)
  53.      (lambda
  54.       (vic name)
  55.       (let ((l (string-length vic)))
  56.     (if (or (zero? (string-length vic))
  57.         (not (char=? #\] (string-ref vic (- l 1)))))
  58.         (string-append vic "[" name "]")
  59.         (string-append (substring vic 0 (- l 1))
  60.                "." name "]")))))
  61.     (else
  62.      (let ((*vicinity-suffix*
  63.         (case (software-type)
  64.           ((NOSVE) ".")
  65.           ((UNIX AMIGA) "/")
  66.           ((MACOS THINKC) ":")
  67.           ((MS-DOS WINDOWS ATARIST OS/2) "\\"))))
  68.        (lambda (vic name)
  69.      (string-append vic name *vicinity-suffix*))))))
  70.  
  71. (define (make-vicinity <pathname>) <pathname>)
  72.  
  73. (define *catalog*
  74.   (map
  75.    (lambda (p)
  76.      (if (symbol? (cdr p)) p
  77.      (cons
  78.       (car p)
  79.       (if (pair? (cdr p))
  80.           (cons 
  81.            (cadr p)
  82.            (in-vicinity (library-vicinity) (cddr p)))
  83.           (in-vicinity (library-vicinity) (cdr p))))))
  84.    '(
  85.      (rev4-optional-procedures    .    "sc4opt")
  86.      (rev2-procedures        .    "sc2")
  87.      (multiarg/and-        .    "mularg")
  88.      (multiarg-apply        .    "mulapply")
  89.      (rationalize        .    "ratize")
  90.      (transcript        .    "trnscrpt")
  91.      (with-file            .    "withfile")
  92.      (dynamic-wind        .    "dynwind")
  93.      (dynamic            .    "dynamic")
  94.      (fluid-let        macro    .    "fluidlet")
  95.      (alist            .    "alist")
  96.      (hash            .    "hash")
  97.      (sierpinski        .    "sierpinski")
  98.      (soundex            .    "soundex")
  99.      (hash-table        .    "hashtab")
  100.      (logical            .    "logical")
  101.      (random            .    "random")
  102.      (random-inexact        .    "randinex")
  103.      (modular            .    "modular")
  104.      (prime            .    "prime")
  105.      (charplot            .    "charplot")
  106.      (sort            .    "sort")
  107.      (common-list-functions    .    "comlist")
  108.      (tree            .    "tree")
  109.      (format            .    "format")
  110.      (format-inexact        .    "formatfl")
  111.      (generic-write        .    "genwrite")
  112.      (pretty-print        .    "pp")
  113.      (pprint-file        .    "ppfile")
  114.      (object->string        .    "obj2str")
  115.      (string-case        .    "strcase")
  116.      (stdio            .    "stdio")
  117.      (scanf            .    "scanf")
  118.      (line-i/o            .    "lineio")
  119.      (string-port        .    "strport")
  120.      (getopt            .    "getopt")
  121.      (debug            .    "debug")
  122.      (trace    defmacro    .    "trace")
  123. ;     (eval            .    "eval")
  124.      (record            .    "record")
  125.      (promise            .    "promise")
  126.      (synchk            .    "synchk")
  127.      (defmacroexpand        .    "defmacex")
  128.      (macro-by-example    defmacro    .    "mbe")
  129.      (syntax-case        .    "scainit")
  130.      (syntactic-closures    .    "scmacro")
  131.      (macros-that-work        .    "macwork")
  132.      (macro            .    macros-that-work)
  133.      (object            .    "object")
  134.      (record-object        .    "recobj")
  135.      (yasos        macro    .    "yasyn")
  136.      (oop            .    yasos)
  137.      (collect        macro    .    "collect")
  138.      (struct    defmacro    .    "struct")
  139.      (structure    syntax-case    .    "structure")
  140.      (values            .    "values")
  141.      (queue            .    "queue")
  142.      (priority-queue        .    "priorque")
  143.      (array            .    "array")
  144.      (array-for-each        .    "arraymap")
  145.      (repl            .    "repl")
  146.      (process            .    "process")
  147.      (test            .    "test")
  148.      (red-black-tree        .    "rbtree")
  149.      (chapter-order        .    "chap")
  150.      (posix-time        .    "time")
  151.      (common-lisp-time        .    "cltime")
  152.      (relational-database    .    "rdms")
  153.      (database-utilities    .    "dbutil")
  154.      (alist-table        .    "alistab")
  155.      (parameters        .    "paramlst")
  156.      (read-command        .    "comparse")
  157.      (match            .    "match-slib")
  158.      (match-slib        .    "match-slib")
  159.      (Gwish            .    "Gwish")
  160.      )))
  161.  
  162. (set! *catalog*
  163.       (cons (cons 'portable-scheme-debugger
  164.           (in-vicinity (sub-vicinity (library-vicinity) "psd")
  165.                    "psd-slib"))
  166.         *catalog*))
  167.  
  168. (define *load-pathname* #f)
  169.  
  170. (define (slib:pathnameize-load *old-load*)
  171.   (lambda (<pathname> . extra)
  172.     (let ((old-load-pathname *load-pathname*))
  173.       (set! *load-pathname* <pathname>)
  174.       (apply *old-load* (cons <pathname> extra))
  175.       (require:provide <pathname>)
  176.       (set! *load-pathname* old-load-pathname))))
  177.  
  178. (set! slib:load-source
  179.       (slib:pathnameize-load slib:load-source))
  180. (set! slib:load
  181.       (slib:pathnameize-load slib:load))
  182.  
  183. ;;;; MODULES
  184.  
  185. (define *modules* '())
  186.  
  187. (define (require:provided? feature)
  188.   (if (symbol? feature)
  189.       (if (memq feature *features*) #t
  190.       (let ((path (cdr (or (assq feature *catalog*) '(#f . #f)))))
  191.         (and path (member path *modules*) #t)))
  192.       (and (member feature *modules*) #t)))
  193.  
  194. (define (require:feature->path feature)
  195.   (if (symbol? feature)
  196.       (if (memq feature *features*) #t
  197.       (let ((path (cdr (or (assq feature *catalog*) '(#f . #f)))))
  198.         (cond ((not path)
  199.            (set! feature (symbol->string feature))
  200.            (if (member feature *modules*) #t
  201.                feature))
  202.           ((symbol? path) (require:feature->path path))
  203.           ((member (if (pair? path) (cdr path) path) *modules*)
  204.            #t)
  205.           (else path))))
  206.       (if (member feature *modules*) #t
  207.       feature)))
  208.  
  209. (define (require:require feature)
  210.   (let ((path (require:feature->path feature)))
  211.     (cond ((eq? path #t) #t)
  212.       ((not path)
  213.        (newline)
  214.        (display ";required feature not supported: ")
  215.        (display feature)
  216.        (newline)
  217.        (slib:error ";required feature not supported: " feature))
  218.       ((not (pair? path))        ;simple name
  219.        (slib:load path)
  220.        (require:provide feature))
  221.       (else                ;special loads
  222.        (require (car path))
  223.        (apply (case (car path)
  224.             ((macro) macro:load)
  225.             ((syntactic-closures) synclo:load)
  226.             ((syntax-case) syncase:load)
  227.             ((macros-that-work) macwork:load)
  228.             ((macro-by-example) defmacro:load)
  229.             ((defmacro) defmacro:load)
  230.             ((source) slib:load-source)
  231.             ((compiled) slib:load-compiled))
  232.           (if (list? path) (cdr path) (list (cdr path))))
  233.        (require:provide feature)))))
  234.  
  235. (define (require:provide feature)
  236.   (if (symbol? feature)
  237.       (if (not (memq feature *features*))
  238.       (set! *features* (cons feature *features*)))
  239.       (if (not (member feature *modules*))
  240.       (set! *modules* (cons feature *modules*)))))
  241.  
  242. (require:provide 'vicinity)
  243.  
  244. (define provide require:provide)
  245. (define provided? require:provided?)
  246. (define require require:require)
  247.  
  248. ;;; Supported by all implementations
  249. (provide 'eval)
  250. (provide 'defmacro)
  251.  
  252. (if (and (string->number "0.0") (inexact? (string->number "0.0")))
  253.     (provide 'inexact))
  254. (if (rational? (string->number "1/19")) (provide 'rational))
  255. (if (real? (string->number "0.0")) (provide 'real))
  256. (if (complex? (string->number "1+i")) (provide 'complex))
  257. (let ((n (string->number "9999999999999999999999999999999")))
  258.   (if (and n (exact? n)) (provide 'bignum)))
  259.  
  260. (define current-time
  261.   (if (provided? 'current-time) current-time
  262.       (let ((c 0))
  263.     (lambda () (set! c (+ c 1)) c))))
  264. (define difftime (if (provided? 'current-time) difftime -))
  265. (define offset-time (if (provided? 'current-time) offset-time +))
  266.  
  267. (define report:print
  268.   (lambda args
  269.     (for-each (lambda (x) (write x) (display #\ )) args)
  270.     (newline)))
  271.  
  272. (define slib:report
  273.   (let ((slib:report (lambda () (slib:report-version) (slib:report-locations))))
  274.     (lambda args
  275.       (cond ((null? args) (slib:report))
  276.         ((not (string? (car args)))
  277.          (slib:report-version) (slib:report-locations #t))
  278.         ((require:provided? 'transcript)
  279.          (transcript-on (car args))
  280.          (slib:report)
  281.          (transcript-off))
  282.         ((require:provided? 'with-file)
  283.          (with-output-to-file (car args) slib:report))
  284.         (else (slib:report))))))
  285.  
  286. (define slib:report-version
  287.   (lambda ()
  288.     (report:print
  289.      'SLIB *SLIB-VERSION* 'on (scheme-implementation-type)
  290.      (scheme-implementation-version) 'on (software-type))))
  291.  
  292. (define slib:report-locations
  293.   (let ((features *features*) (catalog *catalog*))
  294.     (lambda args
  295.       (report:print '(IMPLEMENTATION-VICINITY) 'is (implementation-vicinity))
  296.       (report:print '(LIBRARY-VICINITY) 'is (library-vicinity))
  297.       (report:print '(SCHEME-FILE-SUFFIX) 'is (scheme-file-suffix))
  298.       (cond (*load-pathname*
  299.          (report:print '*LOAD-PATHNAME* 'is *load-pathname*)))
  300.       (cond ((not (null? *modules*))
  301.          (report:print 'Loaded '*MODULES* 'are: *modules*)))
  302.       (let* ((i (+ -1 5)))
  303.     (cond ((eq? (car features) (car *features*)))
  304.           (else (report:print 'loaded '*FEATURES* ':) (display slib:tab)))
  305.     (for-each
  306.      (lambda (x)
  307.        (cond ((eq? (car features) x)
  308.           (if (not (eq? (car features) (car *features*))) (newline))
  309.           (report:print 'Implementation '*FEATURES* ':)
  310.           (display slib:tab) (set! i (+ -1 5)))
  311.          ((zero? i) (newline) (display slib:tab) (set! i (+ -1 5)))
  312.          ((not (= (+ -1 5) i)) (display #\ )))
  313.        (write x) (set! i (+ -1 i)))
  314.      *features*))
  315.       (newline)
  316.       (let* ((i #t))
  317.     (cond ((not (eq? (car catalog) (car *catalog*)))
  318.            (report:print 'Additional '*CATALOG* ':)))
  319.     (cond ((or (pair? args) (not (eq? (car catalog) (car *catalog*))))
  320.            (for-each
  321.         (lambda (x)
  322.           (cond ((eq? (car catalog) x)
  323.              (report:print 'Implementation '*CATALOG* ':)
  324.              (set! i (pair? args))
  325.              (cond (i)
  326.                    (else (display slib:tab) (report:print x)
  327.                      (display slib:tab) (report:print '...)))))
  328.           (cond (i (display slib:tab) (report:print x))))
  329.         *catalog*))
  330.           (else (report:print 'Implementation '*CATALOG* ':)
  331.             (display slib:tab) (report:print (car *catalog*))
  332.             (display slib:tab) (report:print '...))))
  333.       (newline))))
  334.  
  335. (let ((sit (scheme-implementation-version)))
  336.   (cond ((zero? (string-length sit)))
  337.     ((or (not (string? sit)) (char=? #\? (string-ref sit 0)))
  338.      (newline)
  339.      (slib:report-version)
  340.      (report:print 'edit (scheme-implementation-type) ".init"
  341.                'to 'set '(scheme-implementation-version))
  342.      (report:print '(IMPLEMENTATION-VICINITY) 'is (implementation-vicinity))
  343.      (report:print 'type '(slib:report) 'for 'configuration)
  344.      (newline))))
  345.